import random

import math

soup = [{'name': '海蛎豆腐汤', 'price': 18}, {'name': '肉皮酸辣汤', 'price': 18}, {'name': '猪血酸辣汤', 'price': 15},
        {'name': '榨菜肉丝汤', 'price': 12}, {'name': '紫菜蛋花汤', 'price': 12}]
expensive = [{'name': '海蛎抱蛋', 'price': 25}, {'name': '清蒸鲳鱼', 'price': 25}, {'name': '糖醋鱼', 'price': 25},
             {'name': '荔枝肉', 'price': 28}, {'name': '醉排骨', 'price': 28}, {'name': '辣子鸡', 'price': 28},
             {'name': '黄焖鸡', 'price': 28}, {'name': '爆炒鸭胗', 'price': 25}, {'name': '红烧猪蹄', 'price': 25},
             {'name': '蒜苔炒猪耳', 'price': 28}, {'name': '蒜苔炒罗汉肉', 'price': 28}, {'name': '猪肚炒笋', 'price': 28},
             {'name': '红烧带鱼', 'price': 23}, {'name': '爆炒小肠', 'price': 23}, {'name': '爆炒猪心', 'price': 23}]
medium = [{'name': '爆炒猪舌', 'price': 23}, {'name': '爆炒猪肝', 'price': 23}, {'name': '南煎肝', 'price': 23},
          {'name': '干锅包菜', 'price': 18}, {'name': '干锅花菜', 'price': 18}, {'name': '腐竹炒肉片', 'price': 18},
          {'name': '回锅肉', 'price': 18}, {'name': '山药炒木耳', 'price': 18}, {'name': '红烧肉', 'price': 20}]
cheap = [{'name': '葱油花蛤', 'price': 15}, {'name': '虎皮尖椒', 'price': 15}, {'name': '红烧茄子', 'price': 12},
         {'name': '西红柿炒蛋', 'price': 12}, {'name': '酸辣土豆丝', 'price': 10}, {'name': '清炒时蔬', 'price': 10}]

dish_number = [{'soup': 1, 'expensive': 0, 'medium': 2, 'cheap': 2, 'rice': 5},
               {'soup': 1, 'expensive': 1, 'medium': 1, 'cheap': 3, 'rice': 6},
               {'soup': 1, 'expensive': 1, 'medium': 2, 'cheap': 3, 'rice': 7},
               {'soup': 1, 'expensive': 1, 'medium': 2, 'cheap': 4, 'rice': 8},
               {'soup': 1, 'expensive': 2, 'medium': 1, 'cheap': 4, 'rice': 9},
               {'soup': 1, 'expensive': 2, 'medium': 2, 'cheap': 3, 'rice': 10}]

sum_price = 0

sout = True


def how_many_dish(person_number):
    soup_number = dish_number[person_number - 5]['soup']
    expensive_number = dish_number[person_number - 5]['expensive']
    medium_number = dish_number[person_number - 5]['medium']
    cheap_number = dish_number[person_number - 5]['cheap']
    return soup_number, expensive_number, medium_number, cheap_number


def get_rice(person_number):
    global sum_price
    if sout:
        print("饭：" + str(person_number))
    sum_price += person_number


def get_soup(soup_number):
    global sum_price
    temp = []
    count = soup_number
    if sout:
        print("汤：")
    while True:
        ran = random.randint(0, len(soup) - 1)
        if temp.count(ran) == 0:
            temp.append(ran)
            if sout:
                print(soup[ran]['name'] + " " + str(soup[ran]['price']))
            sum_price += soup[ran]['price']
            count -= 1
        else:
            continue
        if count == 0:
            break


def get_expensive(expensive_number):
    global sum_price
    temp = []
    count = expensive_number
    while count != 0:
        ran = random.randint(0, len(expensive) - 1)
        if temp.count(ran) == 0:
            temp.append(ran)
            if sout:
                print(expensive[ran]['name'] + " " + str(expensive[ran]['price']))
            sum_price += expensive[ran]['price']
            count -= 1
        else:
            continue


def get_medium(medium_number):
    global sum_price
    temp = []
    count = medium_number
    while count != 0:
        ran = random.randint(0, len(medium) - 1)
        if temp.count(ran) == 0:
            temp.append(ran)
            if sout:
                print(medium[ran]['name'] + " " + str(medium[ran]['price']))
            sum_price += medium[ran]['price']
            count -= 1
        else:
            continue


def get_cheap(cheap_number):
    global sum_price
    temp = []
    count = cheap_number
    while count != 0:
        ran = random.randint(0, len(cheap) - 1)
        if temp.count(ran) == 0:
            temp.append(ran)
            if sout:
                print(cheap[ran]['name'] + " " + str(cheap[ran]['price']))
            sum_price += cheap[ran]['price']
            count -= 1
        else:
            continue


def how_much(person_number):
    avg = round(sum_price / int(person_number), 2)
    if sout:
        print("共计：" + str(sum_price))
        print("人均约：" + str(avg))
    return avg


def what_to_eat():
    person_number = input("几个人吃(5~10):")
    # person_number = "9"
    per_capita = input("预期人均价格：")
    if person_number.isdigit():
        person_number = int(person_number)
        soup_number, expensive_number, medium_number, cheap_number = how_many_dish(person_number)
        get_soup(soup_number)
        get_rice(person_number)
        if sout:
            print("菜：")
        get_expensive(expensive_number)
        get_medium(medium_number)
        get_cheap(cheap_number)
        return how_much(person_number)
    else:
        print("输入不正确")


if __name__ == "__main__":
    sout = True
    what_to_eat()
